﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using X.PagedList;
using XbsWebAPI.Application.CampRoom.Dtos;
using XbsWebAPI.Application.CampRoom.HouseType;
using XbsWebAPI.Application.CampRoom.Room.Dtos;
using XbsWebAPI.Application.CheckInOut.Dtos;
using XbsWebAPI.Application.Detaileds.Dto;
using XbsWebAPI.Application.Feedback.Dto;
using XbsWebAPI.Application.OrderFinance;
using XbsWebAPI.Application.SystemAdmin.Dtos;
using XbsWebAPI.EntityFrameworkCore.Entities;
using XbsWebAPI.EntityFrameworkCore.Entities.Detailed;
using XbsWebAPI.EntityFrameworkCore.Entities.FeedBack;
using XbsWebAPI.EntityFrameworkCore.Entities.SystemAdmin;

namespace XbsWebAPI.Application
{
    /// <summary>
    /// 静态全局 AutoMapper 配置文件
    /// </summary>
    public class AutoMapperConfig
    {
        public static MapperConfiguration RegisterMappings()
        {
            //创建AutoMapperConfiguration, 提供静态方法Configure，一次加载所有层中Profile定义 
            //MapperConfiguration实例可以静态存储在一个静态字段中，也可以存储在一个依赖注入容器中。 一旦创建，不能更改/修改。
            return new MapperConfiguration(cfg =>
            {
                //这个是领域模型 -> 视图模型的映射，是 读命令
                cfg.AddProfile(new DomainToViewModelMappingProfile());
                //这里是视图模型 -> 领域模式的映射，是 写 命令
                cfg.AddProfile(new ViewModelToDomainMappingProfile());
            });
        }
    }

    public class DomainToViewModelMappingProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public DomainToViewModelMappingProfile()
        {
            //CreateMap<Camp, CreateCampDto>()
            //    .ForPath(d => d.Name, o => o.MapFrom(s => s.Name))
            //    .ForPath(d => d., o => o.MapFrom(s => s.CampService))
            //    .ForPath(d => d.CampService, o => o.MapFrom(s => s.Address.County))
            //    .ForPath(d => d.Street, o => o.MapFrom(s => s.Address.Street)); ;

            //CreateMap<Camp, CreateCampDto>();
            //CreateMap<CampImage, CreateCampImageDto>();
            //CreateMap<CampImage, EditCampImageDto>();
            CreateMap<HouseType, GetHouseTypeRoomDto>();

            CreateMap<SystemRole, ListSystemRoleDto>();
            CreateMap<SystemRole, GetSystemRoleDto>();

            CreateMap<XbsAdminUser, ListAdminUserDto>();

            CreateMap<CheckIn, ListCheckInDto>();
            CreateMap<Room, RoomDto>();
            CreateMap<HouseType, HouseTypeDto>();



            CreateMap<Camp, ListCampDto>();
            CreateMap<Camp, SelectCampDto>();
            CreateMap<CampImage, EditCampImageDto>();
            CreateMap<Camp, GetCampDto>();
            //CreateMap<HouseTypePicture, CreateHouseTypePictureDto>();
            //CreateMap<Camp, SelectCampDto>();
            //CreateMap<SupportingFacility, CreateSupportingFacilityDto>();
            //CreateMap<SupportingFacility, EditSupportingFacilityDto>();
            CreateMap<HouseTypeSupportingFacility, ListSupportingFacilityDto>();
            CreateMap<SupportingFacility, ListSupportingFacility>();
            CreateMap<HouseType, ListHouseTypeDto>();

            //CreateMap<Camp, EditCampDto>();
           

            //CreateMap<HouseTypeHoliday, CreateHouseTypeHolidayDto>();
            //CreateMap<HouseTypeHoliday, EditHouseTypeHolidayDto>();
            CreateMap<HouseTypeHoliday,ListHouseTypeHolidayDto>();
            CreateMap<HouseTypeHoliday,GetHouseTypeHolidayDto>();

            
            
            CreateMap<HouseTypeSpecialDay, ListHouseTypeSpecialDayDto>();
            CreateMap<HouseTypeSpecialDay, GetHouseTypeSpecialDayDto>();
            

            CreateMap<HouseType, GetHouseTypeBasicDto>();
            CreateMap<HouseTypePicture, HouseTypePictureDto>();

            CreateMap<Guest, ListGuestDto>();
            CreateMap<Guest, GetGuestDtoNew>();
            CreateMap<MiniProgram, SetMiniProgramDto>();

            //房间管理
            CreateMap<Room, ListRoomDto>();
            CreateMap<Room, GetRoomDto>();

            //房态管理
            CreateMap<HouseType, SelectHouseTypeDto>();
            CreateMap<HouseType, CreateHouseTypeBasicDto>();

            CreateMap<CreateBindRoomDto, Room>();
            CreateMap<Room, CreateBindRoomDto>();

            //意见反馈
            CreateMap<FeedBack, FeedBackDto>();
            CreateMap<FeedBack, ListFeedBackDto>();

            CreateMap<CheckOut, ListCheckOutDto>();
            CreateMap<OrderDetail, ListOrderDetailDto>();
        }
    }

    public class ViewModelToDomainMappingProfile : Profile
    {
        public ViewModelToDomainMappingProfile()
        {
            //手动进行配置
            //CreateMap<OrderViewModel, Order>()
            //    .ForPath(d => d.Address.Province, o => o.MapFrom(s => s.Province))
            //    .ForPath(d => d.Address.City, o => o.MapFrom(s => s.City))
            //    .ForPath(d => d.Address.County, o => o.MapFrom(s => s.County))
            //    .ForPath(d => d.Address.Street, o => o.MapFrom(s => s.Street))
            //    .ForPath(d => d.OrderItem, o => o.MapFrom(s => s.Items));

            CreateMap<CreateCampDto, Camp>();
            CreateMap<CreateCampImageDto, CampImage>();
            CreateMap<EditCampImageDto, CampImage>();

            CreateMap<CreateMenuDto, Menu>();
            CreateMap<EditMenuDto, Menu>();
            CreateMap<CreateSystemRoleDto, SystemRole>();
            CreateMap<EditSystemRoleDto,SystemRole>();

            //CreateMap<ListCampDto, Camp>();
            //CreateMap<SelectCampDto, Camp>();
            CreateMap<CreateHouseTypePictureDto, HouseTypePicture>();
            //CreateMap<SelectCampDto, Camp>();
            CreateMap<CreateSupportingFacilityDto, SupportingFacility>();
            CreateMap<EditSupportingFacilityDto,SupportingFacility>();
            //CreateMap<ListHouseTypeDto, HouseType>();
            CreateMap<EditCampDto, Camp>();
            CreateMap<GetCampDto, Camp>();
            CreateMap<CreateHouseTypeHolidayDto, HouseTypeHoliday>();
            CreateMap<EditHouseTypeHolidayDto, HouseTypeHoliday>();
            //CreateMap<ListHouseTypeHolidayDto, HouseTypeHoliday>();
            CreateMap<GetHouseTypeHolidayDto, HouseTypeHoliday>();

            CreateMap<CreateHouseTypeSpecialDayDto, HouseTypeSpecialDay>();
            CreateMap<EditHouseTypeSpecialDayDto, HouseTypeSpecialDay>();

            //新建/编辑 房型
            CreateMap<CreateHouseTypeBasicDto, HouseType>();
            CreateMap<EditHouseTypeBasicDto, HouseType>();
            CreateMap<SetHouseTypePriceDto, HouseType>();

            //房客管理
            CreateMap<CreateGuestDto, Guest>();
            CreateMap<EditGuestDto, Guest>();
            CreateMap<SetMiniProgramDto, MiniProgram>();

            //房间管理
            CreateMap<EditRoomDto, Room>();
            CreateMap<CreateRoomDto, Room>();

            CreateMap<EditCampImageDto,CampImage>();

            CreateMap<ListSupportingFacilityDto, HouseTypeSupportingFacility>();

            CreateMap<FeedBackDto, FeedBack>();

            //收入明细
            CreateMap<Detailed, CreateDetailedDto>();
            CreateMap<CreateDetailedDto, Detailed>();
        }
    }

}
